package com.tpp.order.config;

import com.tpp.comm.util.TpConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
/**
 * 订单延时队列
 */
public class RabbitDelayedConfig {

    //创建队列
    @Bean
    public Queue orderDelayedQueue(){
        return QueueBuilder
                .durable(TpConst.Rabbit.ORDER_DELAYED_QUEUE)
                .deadLetterRoutingKey(TpConst.Rabbit.ORDER_DEAD_QUEUE)
                .deadLetterExchange("")
                .build();
    }

    //订单延时队列交换机
    @Bean
    public Exchange orderDelayedExchange(){
        return ExchangeBuilder
                .directExchange(TpConst.Rabbit.ORDER_DELAYED_EXCHANGE)
                .build();
    }

    //绑定到订单的交换机中
    @Bean
    public Binding orderDelayedBind(){
        return BindingBuilder
                .bind(orderDelayedQueue())
                .to(orderDelayedExchange())
                .with(TpConst.Rabbit.ORDER_DELAYED_QUEUE)
                .noargs();

    }


}
